import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';

import { IncomingHttpHeaders } from 'http';

import { systemid } from '../atom/config';

interface Message {
	filter: {
		[key: string]: string
	};
	page_no: number;
}


interface IRes {
	_id: string;
	category_no: string;
	category_name: string;
	description: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:home1\s001,action_id:' + action_id);

	const { exec, prepare } = query(action_id, session_id, systemid);
	prepare('commodity', ['commodity_name'], message.filter, 5, 1, [], []);
	const [data] = await exec<IRes>();

	log('Service end path:home1\s001,action_id:' + action_id);
	return {
		data
	};
}
